<template>
  <el-dropdown trigger="click" @command="handleSetLanguage" >
    <div class="lang" :class="marginLang">
      <el-button round type="primary">
        <el-tooltip :content="$t('lang.many')" effect="dark" placement="bottom">
          <svg-icon
              style="width: 1.5em;height: 1.5em;"
              class-name="international-icon"
              icon-class="i18n-black" />
        </el-tooltip>
        <h3 style="color: #000000">&nbsp;{{ $t('lang.lang') }}</h3>
      </el-button>
    </div>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item :disabled="language==='zh'" command="zh">
          中文
        </el-dropdown-item>
        <el-dropdown-item :disabled="language==='en'" command="en">
          English
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script setup>
import Select from '@/components/LangSelect/Select.vue'
import {computed} from 'vue'
import useI18NStore from "@/store/modules/i18n";

const i18nStore = useI18NStore()

const { proxy } = getCurrentInstance();

const marginLang = ref('zh');


const language = computed(()=> {
  //return this.$store.getters.language
  return i18nStore.language
})

function handleSetLanguage(lang) {
  proxy.$i18n.locale = lang
  marginLang.value = lang
  i18nStore.setLanguage(lang)
  proxy.$message({
    message: proxy.$t('lang.message'),
    type: 'success'
  })
}
function init(){
  console.log(language)
}
init();
</script>
<style scoped>
.lang {
  font-size: large;
  color: #707070;
  padding: 1px;
  margin-left: 245px;
}
.en {
  margin-left: 201px;
}
.zh {
  margin-left: 242px;
}
</style>
